var app = getApp()
var citys = require('../../../../utils/citys.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    step: 1,
    cityData: [],
    region: [],
    isindex: 1,
    ischeck: true,
    issuss: false,
    logo: '',
    array: ['一甲', '二甲', '三甲'],
    index: 0,
    modes: ['药房', '医院', '机构'],
    indexs: 0
  },
  bindRegionChange: function (e) {
    console.log(e);
    this.setData({
      cityData: e.detail.value,
      isindex: 0
    })
  },
  bindPickerChange: function (e) {
    this.setData({
      index: e.detail.value
    })
  },
  bindModesChange: function (e) {
    this.setData({
      indexs: e.detail.value
    })
  },
  gotkhome: function () {
    wx.navigateTo({
      url: '/hyb_yl/mycenter/pages/Organ/Organ',
    })
  },
  gotkagin: function () {
    this.setData({
      step: 1
    })
  },
  chooseimg: function () {
    var that = this;
    wx.chooseImage({
      count: 1, // 默认9
      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
      success: function (res) {
        console.log(res)
        var tempFilePaths = res.tempFilePaths
        that.setData({
          logo: tempFilePaths,
          // picflag: false
        })
      }
    })
  },
  formSubmit: function (e) {
    console.log(e);
    const that = this;
    const names = e.detail.value.names;
    const tel = e.detail.value.tel;
    const city = that.data.cityData;
    const check = that.data.ischeck;
    const comname = e.detail.value.comname;
    const address = e.detail.value.address;
    if (that.data.logo == "") {
      wx.showToast({
        title: '请您上传logo图片',
        icon: 'none'
      })
      return;
    } else if (comname == "") {
      wx.showToast({
        title: '请输入机构名称',
        icon: 'none'
      })
      return;
    } else if (city.length == 0) {
      wx.showToast({
        title: '请选择所在地',
        icon: 'none'
      })
      return;
    } else if (address == "") {
      wx.showToast({
        title: '请输入您的详细地址',
        icon: 'none'
      })
      return;
    } else if (names == '') {
      wx.showToast({
        title: '请输入负责人姓名',
        icon: 'none'
      })
      return;
    } else if (tel == '') {
      wx.showToast({
        title: '请输入您的手机号',
        icon: 'none'
      })
      return;
    } else if (!(/^1[34578]\d{9}$/.test(tel))) {
      wx.showToast({
        title: '请输入正确的手机号',
        icon: 'none'
      })
      return;
      if (phone.length >= 11) {
        wx.showToast({
          title: '手机号有误',
          icon: 'none'
        })
        return;
      }
    }



    wx.showToast({
      title: '提交成功',
    })
    setTimeout(function () {
      that.setData({
        step: 2
      })
    }, 800)

  },
  checkboxChange: function (e) {
    console.log(e);
    const value = e.detail.value.length;
    if (value == 0) {
      this.setData({
        ischeck: false
      })
    } else {
      this.setData({
        ischeck: true
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.getjigouif()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  getjigouif() {
    var that = this
    app.util.request({
      url: "entry/wxapp/regin.jigouif",
      data: {
        openid: wx.getStorageSync('openid')
      },
      success: function (resing) {
        console.log(resing)
        that.setData({
          state: resing.data.state,
          detail:resing.data
        })
      }
    })
  },
})